<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
	<title>前后端交互-登录案例</title>
</head>
<body>


<span>用户名：</span><input type="text" class="username" name=""><br/>
<span>密码：</span><input type="text" class="password" name=""><br/>
<button>用户登录</button>	

<script src="jquery-1.9.1.min.js"></script>
<script>
	$('button').click(function(){
		$.ajax({
			type:'post',
			url:'ajax2.php',
			dataType:'json',
			data:{
				myUname:$('.username').val(),
				myUpass:$('.password').val()
			},
			success:function(res){
				console.log(res);
				if(res.infoCode == 0){
					alert('登陆成功');
				}else if(res.infoCode == 1){
					alert('登录失败,用户名或密码错误');
				}else{
					alert('网络连接失败，请检查网络连接！');
				}
			}
		});
	});
</script>

</body>
</html>